<#include "/common/include.html"/>
<@pageTheme mark="${config.optimize()?string('true', 'false')}">
<@header title="修改公司"/>
<@addorEdit fromId="form-comp-edit">
	<input id="compId" name="compId" type="hidden" value="${comp.compId}"   />
	<input id="parentId" name="parentId" type="hidden" value="${comp.parentId}"   />
	<input id="deptId" name="deptIdList" type="hidden" value="${deptIdList}"/>
	<div class="form-group">
		<label class="col-sm-3 control-label "><span style="color: red; ">*</span>上级公司：</label>
		<div class="col-sm-8">
			<div class="input-group">
				<input class="form-control" type="text" onclick="selectCompTree()" id="compName" readonly="true" value="${comp.parentName?default("总公司")}">
				<span class="input-group-addon"><i class="fa fa-fw fa-search"></i></span>
			</div>
		</div>
	</div>
	<div class="form-group">
		<label class="col-sm-3 control-label"><span style="color: red; ">*</span>名称：</label>
		<div class="col-sm-8">
			<input class="form-control" type="text" id="name" name="name" value="${comp.name}"  required>
		</div>
	</div>
	<div class="form-group">
		<label class="col-sm-3 control-label "><span style="color: red; ">*</span>管理地区：</label>
		<div class="col-sm-8">
			<div class="input-group">
				<input class="form-control" type="text" onclick="selectDeptTree()" id="deptName" value="${deptName}" readonly="true">
				<span class="input-group-addon"><i class="fa fa-fw fa-search"></i></span>
			</div>
		</div>
	</div>
	<div class="form-group">
		<label class="col-sm-3 control-label">显示排序：</label>
		<div class="col-sm-8">
			<input class="form-control" type="text" name="orderNum"  value="${comp.orderNum?default("0")}"  required>
		</div>
	</div>
	<div class="form-group">
		<label class="col-sm-3 control-label"><span style="color: red; ">*</span>状态：</label>
		<div class="col-sm-8">
			<#list dict.getType('sys_normal_disable')>
				<#items as d>
					<#if d.status =='0' >
						<div class="radio-box">
							<input type="radio" id="${d.dictCode}" name="status"
								   value="${d.dictValue}" <#if d.dictValue == comp.status >checked</#if>>
							<label for="${d.dictCode}" text="${d.dictLabel}">${d.dictLabel}</label>
						</div>
					</#if>
				</#items>
			</#list>
		</div>
	</div>
	<div class="form-group">
		<label class="col-sm-3 control-label">备注：</label>
		<div class="col-sm-8">
			<textarea id="remark" name="remark" class="form-control">${comp.remark?default("")}</textarea>
		</div>
	</div>
</@addorEdit>
<@footer>
	<script>
		var prefix = baseURL + "sys/comp";
		
		$("#form-comp-edit").validate({
			onkeyup: false,
			rules:{
				name:{
					remote: {
		                url: prefix + "/checkCompNameUnique",
		                type: "POST",
		                dataType: "html",
		                data: {
		                	"parentId": function() {
		                		return $("input[name='parentId']").val();
		                    },
		                	"name" : function() {
		                        return opt.common.trim($("#name").val());
		                    },
							"compId":function() {
								return opt.common.trim($("#compId").val());
							}
		                },
		                dataFilter: function(data, type) {
		                	return opt.validate.unique(data);
		                }
		            }
				},
				orderNum:{
					digits:true
				}
			},
			messages: {
		        "name": {
		            remote: "已经存在"
		        }
		    },
		    focusCleanup: true
		});
		
		function submitHandler() {
	        if (opt.validate.form()) {
				var options = {
					id:'form-comp-edit',
					conversion:[
						{
							name:'deptIdList',
							value:'arr'
						}
					]
				};
				var data = opt.form.dataUp(options);
	        	opt.operate.save(prefix + "/edit", data);
	        }
	    }
	
		/*部门管理-新增-选择父部门树*/
		function selectCompTree() {
			var options = {
				title: '公司选择',
				width: "380",
				url: prefix + "/selectCompTree/" + $("#parentId").val(),
				callBack: doSubmit
			};
			opt.modal.openOptions(options);
		}
		
		function doSubmit(index, layero){
			var _v = $.tree.callBackTree(layero,index);
   			$("#parentId").val(_v.id);
   			$("#compName").val(_v.name);
   			layer.close(index);
		}

		/*获取公司对应地区*/
		function selectDeptTree(){
			var options = {
				title:"<@ctx.i18n text = "sys.select.dept"/>",
				width: "380",
				url: baseURL+'sys/dept/selectDeptTree',
				obj:{"compId":$("#parentId").val(),"list":$("#deptId").val()},
				callBack: DeptDoSubmit
			};
			opt.modal.openOptions(options);
		}
		function DeptDoSubmit(index, layero){
			var _v = $.tree.callBackTree(layero,index);
			$("#deptId").val(_v.id);
			$("#deptName").val(_v.name);
			layer.close(index);
		}
	</script>
</@footer>
</@pageTheme>
